<template>
  <a-radio-group
    v-model="value"
    :options="formatterOptions"
    v-bind="$attrs"
  >
  </a-radio-group>
</template>

<script>
export default {
  name: "search-radio",
  inheritAttrs: false,

  data() {
    return {
      value: undefined,
    };
  },
  computed: {
    formatterOptions() {
      let formatter = this.$attrs.options;
      if (this.$attrs.fieldNames) {
        formatter = this.$attrs.options.map((item) => {
          return {
            value: item[this.$attrs.fieldNames.value],
            label: item[this.$attrs.fieldNames.label],
          };
        });
        return formatter;
      }
    },
  },
  mounted() {
    // 设置单选默认值
    if (this.$attrs.defaultValue || typeof this.$attrs.defaultValue === 'number') {
      this.$emit("change", this.$attrs.defaultValue);
    }
  },
  methods: {
    // 选项发生改变
    // handleChange(evt) {
    //   if (evt) {
    //     this.$emit("change", evt.target.value);
    //   }
    // },
  },
};
</script>

<style>
</style>
